<%--
  Created by IntelliJ IDEA.
  User: 10732
  Date: 24/2/2022
  Time: 下午 7:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/public.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/style.css"/>
</head>
<body>
<!--头部-->
<%@ include file="common/publicTop.jsp" %>
<!--时间-->
<section class="publicTime">
    <span id="time">2015年1月1日 11:11  星期一</span>
    <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
</section>
<!--主体内容-->
<section class="publicMian ">
    <%@ include file="common/publicLeft.jsp" %>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>用户管理页面</span>
        </div>
        <div class="search">
            <form style="float:left;" action="${pageContext.request.contextPath}/userList" method="post">
            <span>用户名：</span>
                <input name="keyName" type="text" value="${keyName}" placeholder="请输入用户名"/>
            <span>用户角色：</span>
                <select name="rid">
                    <option value="0">--请选择--</option>
                <c:forEach items="${roles}" var="role" >
                    <option value="${role.id}" ${role.id==rid?'selected':''} >${role.roleName}</option>
                    </c:forEach>
                </select>
            <input type="submit" value="查询"/>
            </form>
            <a href="${pageContext.request.contextPath}/toAddUser">添加用户</a>
        </div>
        <!--用户-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">用户编码</th>
                <th width="20%">用户名称</th>
                <th width="10%">性别</th>
                <th width="10%">年龄</th>
                <th width="10%">电话</th>
                <th width="10%">用户类型</th>
                <th width="30%">操作</th>
            </tr>
            <c:forEach items="${users.list}" var="user">
            <tr>
                <td>${user.userCode}</td>
                <td>${user.userName}</td>
                <td>${user.gender==1?'女':'男'}</td>
                <td>${user.age}</td>
                <td>${user.phone}</td>
                <td>${user.role.roleName}</td>

                <td>
                    <a href="${pageContext.request.contextPath}/toview/${user.id}"><img src="${pageContext.request.contextPath}/statics/img/read.png" alt="查看" title="查看"/></a>
                    <a href="${pageContext.request.contextPath}/toupdate/${user.id}"><img src="${pageContext.request.contextPath}/statics/img/xiugai.png" alt="修改" title="修改"/></a>
                    <a id="${user.id}" href="javascript:void (0)" class="removeUser"><img src="${pageContext.request.contextPath}/statics/img/schu.png" alt="删除" title="删除"/></a>
                </td>
            </tr>
            </c:forEach>
        </table>
        <p align="center">
        <c:choose>
            <c:when test="${users.pageNum>1}">
                <a href="${pageContext.request.contextPath}/userList?pageNum=1&keyName=${keyName}&rid=${rid}">首页</a>
                <a href="${pageContext.request.contextPath}/userList?pageNum=${users.pageNum-1}&keyName=${keyName}&rid=${rid}">上一页</a>
            </c:when>
            <c:otherwise>
                首页
                上一页
            </c:otherwise>
        </c:choose>
        [${users.pageNum}/${users.pages}]
        <c:choose>
            <c:when test="${users.pageNum<users.pages}">
                <a href="${pageContext.request.contextPath}/userList?pageNum=${users.pageNum+1}&keyName=${keyName}&rid=${rid}">下一页</a>
                <a href="${pageContext.request.contextPath}/userList? pageNum=${users.pages}&keyName=${keyName}&rid=${rid}">末页</a>
            </c:when>
            <c:otherwise>
                下一页
                末页
            </c:otherwise>
        </c:choose>
        </p>
        <p>
            总数据量：${users.total}
        </p>

    </div>
</section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeUse">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该用户吗？</p>
            <a href="javascript:void(0)" id="yes">确定</a>
            <a href="javascript:void(0)" id="no">取消</a>
        </div>
    </div>
</div>

<%@ include file="common/publicBottom.jsp" %>

<script src="${pageContext.request.contextPath}/statics/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/statics/js/js.js"></script>
<script src="${pageContext.request.contextPath}/statics/js/time.js"></script>
<script>
    //用户管理页面上点击删除按钮弹出删除框(userList.html)
     $(function (){

         var delUserId;
         $('.removeUser').click(function () {
             $('.zhezhao').css('display','block');
             $('#removeUse').fadeIn();
             delUserId = $(this).attr("id");
         });
         $("#yes").click(function() {
             $('.zhezhao').css('display','none');
             $('#removeUse').fadeOut();
             $.ajax({
                 "url":"${pageContext.request.contextPath}/deleteUser",
                 "type":"post",
                 "data":"id="+delUserId,
                 "success":function(data){
                     if(data=="success"){
                         location.href="${pageContext.request.contextPath}/userList";
                     }
                 }
             });
         });
     });
</script>


</body>
</html>
